<?php

namespace App\Console\Commands;

use App\exption\jhsms\Jhsms;
use App\Models\User;
use App\Models\UserInvitationCode;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class monitoring extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature  = 'monitoring:send {action}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '监控脚本';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // 获取参数，调用方法
        $action = $this->argument('action');
        $this->$action();
    }

    /*
     * 监控用户邀请码是否有异常
     * */
    public function check_user_code()
    {
        // 半夜不检测
        $housr = (int)date("H", time());
        if($housr <= 9 && $housr >= 22)
            return true;

        $mobile = '13926517448';
        // 获取用户总数
        $total_user = User::where([['status', '=', 1]])->count();
        $total_user_code = UserInvitationCode::count();

        // 数据异常
        if($total_user != $total_user_code){
            $monitoring_sms_status = config('basic.monitoring.monitoring_sms_status');
            if($monitoring_sms_status != true)
                return true;
            $str ='邀请码异常';
            $sms = new Jhsms();
            $sms->send_info($mobile, $str, '146731');
        }
    }

}
